package com.example.manbook.controller;

import com.example.manbook.service.ResultService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.io.IOException;
import java.util.List;

@Controller
public class CmdController {
    @Autowired
    private ResultService resultService;

    @GetMapping("/man/{dir}/{cmd}.html")
    public String cmdModel(Model model, @PathVariable String dir, @PathVariable String cmd) throws IOException {
        List<String> stringList = resultService.execInfo(cmd, Integer.parseInt(dir.substring(3)));
        model.addAttribute("strs", stringList);
        return "cmd.html";
    }
}
